//
// Created by hugan on 2020/10/17.
//

#ifndef JOYSTICKCPP_COMMONUTIL_H
#define JOYSTICKCPP_COMMONUTIL_H

#include <iostream>
#include <sstream>
#include <process.h>
#include <windows.h>
#include <strsafe.h>
#include <cstring>
#include <dinput.h>

using namespace std;

class CommonUtil {
public://common
    constexpr static const HRESULT INPUT_LOST = -2147220983;

    /**
     * 获取控制台输入的行数据,阻塞当前线程
     * @param msg 阻塞线程前的文本消息
     */
    static char *getInputLine(const char *msg);

    /**
     * 在新线程中监听用户输入,然后触发pExitFunction回调
     */
    static void startExitInputThread(void (*pExitFunction)());

public://DInput
    static bool FAILED2(const string& desc, HRESULT hr);

    /**
     * 打印设备状态
     * @param state
     * @param allField 是否打印全部属性
     */
    static void printDeviceState(DIJOYSTATE2 *state, bool allField);

};

#endif //JOYSTICKCPP_COMMONUTIL_H
